package com.example.secondhandsysapi.Mapper;

import com.example.secondhandsysapi.Entity.GoodsInfo;
import com.example.secondhandsysapi.Vo.CategoryGoodsInfo;
import com.example.secondhandsysapi.Vo.GoodsPostInfo;
import org.apache.ibatis.annotations.*;

import java.sql.Date;
import java.util.List;
@Mapper
public interface GoodsInfoMapper {

    //前端查询
    @Select("select * from goods_info where goods_name like'%${name}%'")
    List<GoodsInfo> getAllGoodsInfo(String name);
    @Delete("delete from goods_info where  goods_id=#{goodsid} ")
    Integer deleteById(Integer goodsid);
    @Select("select * from goods_info where goods_price like'%${price}%'")
    List<GoodsInfo> getAllGoodsInfoByPrice(Integer price);//调用对应的方法
    @Select("select *from goods_info where goods_name like'%$goodsName%' and'%$goodsPrice%' = 12")
    List<GoodsInfo> getAllGoodsInfoByPriceAndName(String goodsName,Integer goodsPrice);

    //得到商品审核信息
    @Select("select user_id,goods_id,goods_name,goods_image,goods_description,goods_price,check_info from goods_info where goods_checkid = 0 AND (user_id = #{user_id} and goods_name like '%${goods_name}%')")
    List<GoodsInfo> getAllUpdateGoodsInfo(@Param("user_id") Integer user_id, @Param("goods_name") String goods_name);
    @Select("select user_id,goods_id,goods_name,goods_image,goods_description,goods_price,check_info from goods_info where goods_checkid = 0")
    List<GoodsInfo> getAllGoodsInfo1();
    @Select("select user_id,goods_id,goods_name,goods_image,goods_description,goods_price,check_info from goods_info where goods_checkid = 0 and goods_name like '%${goods_name}%' ")
    List<GoodsInfo> getAllGoodsInfoByName(@Param("goods_name") String goods_name);
    @Select("select user_id,goods_id,goods_name,goods_image,goods_description,goods_price,check_info from goods_info where goods_checkid = 0 and user_id = #{user_id}")
    List<GoodsInfo> getAllGoodsInfoByID(@Param("user_id") Integer user_id);

    //通过时对status进行修改
    @Select("UPDATE goods_info SET goods_checkid = 1 WHERE goods_id = #{goods_id}")
    Integer updateStatus(@Param("goods_id") Integer goods_id);

    //拒绝时对status进行修改
    @Select("UPDATE goods_info SET check_info = #{check_info},goods_checkid = 2 WHERE goods_id=#{goods_id}")
    Integer updateCheck_Info(@Param("check_info") String check_info,@Param("goods_id") Integer goods_id );

    //商品发布页面插入商品信息
    @Insert("insert into goods_info(user_id,goods_name,goods_price,goods_stock,goods_description,goods_image,category_id) \n" +
            "values(#{user_id},#{goods_name},#{goods_price},#{goods_stock},#{goods_description},#{goods_image},#{category_id})")
    Integer insertGoodsInfo(GoodsPostInfo goodsPostInfo);

    //主页商品推荐随机抽取数据库中八条商品信息
    @Select("SELECT * FROM goods_info ORDER BY RAND() LIMIT 8")
    List<GoodsInfo> getRandomGoodsInfo();

    //得到对应用户已发布的商品
    @Select("select * from goods_info join user_info on user_info.user_id=goods_info.user_id where user_info.user_id=#{user_id} and goods_checkid=1")
    List<GoodsPostInfo> getPublicProduct(@Param("user_id") Integer user_id);

    //我发布的商品，点击修改回显商品信息
    @Select("select * from goods_info where goods_id=#{id}")
    List<GoodsInfo> getProductDetailById(@Param("id") Integer id);

    //修改已发布的商品信息
    @Update("update goods_info set goods_name=#{goods_name},goods_price=#{goods_price},goods_stock=#{goods_stock},goods_description=#{goods_description},goods_image=#{goods_image},category_id=#{category_id},goods_checkid=0 \n" +
            "where goods_id=#{goods_id}")
    Integer updateProductInfo(GoodsInfo goodsInfo);

    //前端
    //根据时间和品牌进行筛选
    @Select("SELECT goods_id,goods_name,goods_price,goods_post,goods_description,goods_image FROM goods_info WHERE goods_post like CONCAT('%', #{goods_post}, '%') and category_id=#{category_id}")
    List<GoodsInfo> getAllGoodsInfoPostCategory(Date goods_post, Integer category_id);

    @Select("SELECT goods_id,goods_name,goods_price,goods_post,goods_description,goods_image FROM goods_info WHERE goods_post like CONCAT('%', #{goods_post}, '%') ")
    List<GoodsInfo> getAllGoodsInfoPost(Date goods_Post);

    @Select("SELECT goods_id,goods_name,goods_price,goods_post,goods_description,goods_image FROM goods_info WHERE  category_id=#{category_id}")
    List<GoodsInfo> getAllGoodsInfoCategory(Integer category_id);

    @Select("SELECT goods_id,goods_name,goods_price,goods_post,goods_description,goods_image FROM goods_info ")
    List<GoodsInfo> getAllGoodsInfo3();

    @Select("select  goods_name,goods_description,goods_image, goods_price,goods_stock from goods_info where goods_id =#{goods_id}")
    List<GoodsInfo> getAllGoodsDetailsInfoByGoodsId(Integer goodsId);

    @Select("select goods_id,goods_name,goods_price,goods_image,goods_info.category_id,category_name,category_description,category_image from goods_info join category on goods_info.category_id=category.category_id where goods_info.category_id =#{category_id}")
    List<CategoryGoodsInfo> getAllCategoryGoodsId(@Param("category_id") Integer category_id);

    @Select("SELECT goods_id, goods_name, goods_image  \n" +
            "FROM goods_info  \n" +
            "WHERE category_id = #{category_id} \n" +
            "ORDER BY RAND()  \n" +
            "LIMIT 3; ")
    List<GoodsInfo> getAllGoodsInfoByCategoryId(Integer category_id);

    //前端根据商品名称查询
    @Select("select goods_id,goods_image,goods_name,goods_description,goods_price from goods_info where goods_name likeCONCAT('%', #{goods_name}, '%')")
    List<GoodsInfo> getAllGoodsInfoName(String goods_name);

    //根据商品名称查询
    @Select("select * from goods_info where goods_name like'%${name}%'")
    List<GoodsInfo> getAllGoodsInfoByNa(String name);

    //后端商品管理页面
    @Select("select * from goods_info")
    List<GoodsInfo> getAllBackendGoodsInfo();
}

